package top.atcra.dubbo;

import org.apache.dubbo.config.*;

import java.io.IOException;

public class Provider {
    public static void main(String[] args) throws IOException {
        //暴露SayHello服务
        //1、application
        ApplicationConfig applicationConfig = new ApplicationConfig("sample-provider");
        //2、protocol -dubbo协议
        ProtocolConfig protocolConfig = new ProtocolConfig();
        protocolConfig.setName("dubbo");
        protocolConfig.setPort(20880);
        //3、register
        //直连的方式，不暴露到注册中心
        RegistryConfig registryConfig = new RegistryConfig("zookeeper://npu1.atcra.top:2181");
        //4、service
        ServiceConfigBase<SayHello> serviceConfig = new ServiceConfig<>();
        serviceConfig.setInterface(SayHello.class);
        serviceConfig.setRef(new SayHelloImpl());
        //5、将application、protocol、register注册到service
        serviceConfig.setRegistry(registryConfig);
        serviceConfig.setProtocol(protocolConfig);
        serviceConfig.setApplication(applicationConfig);
        serviceConfig.export();

        System.out.println("服务已经暴露");
        System.in.read();
    }
}
